/**
 * This program is an adaption of the "BasicMeasure.ino" which was in the "RigExpertZeroII_UART/examples/BasicMeasure/" 
 * directory of the "RigExpertZeroII_UART.zip" file on RigExpert's website.
 * @see https://rigexpert.com/files/libraries/RigExpertZeroII_UART/RigExpertZeroII_UART.zip
 * 
 * Connect an arduino nano to the rigexpert zeroII:
 * 
 *     ARDUINO NANO ->  ZEROII
 *     --------------------------
 *     PIN 4 (RX)   ->  TX
 *     PIN 7 (TX)   ->  RX
 *     PIN 2        ->  RST
 *     PIN X (+5V)  ->  POWER +
 *     PIN X (GND)  ->  POWER -
 *     
 * For testing purposes the frequency was fixed at 14Mhz and the antenna tuned with a tuner 
 * in order to show the different SWR values.
 * 
 * @attention: The original BasicMeasure.ino only did measure 3 times before the values freezed.
 * 
 */
#include "RigExpertZeroII_UART.h"

#define RX_PIN 4
#define TX_PIN 7
#define ZEROII_Reset_Pin  2

RigExpertZeroII_UART ZERO(RX_PIN, TX_PIN);

int32_t counter=0; 
const int32_t FREQ=140000000; // 14 000 000 Hz // 14 Mhz

void setup()
{ 
    pinMode(ZEROII_Reset_Pin, OUTPUT);
    digitalWrite(ZEROII_Reset_Pin, LOW);
    Serial.begin(38400);
    Serial.flush();
    digitalWrite(ZEROII_Reset_Pin, HIGH );
    while(!ZERO.startZeroII())
    {     
        Serial.println("ZERO not found!");
        delay(500);
    }
    Serial.println("----------------------------");
    Serial.println("Found RigExpert ZEROII!");
    String str = "Version: ";
    Serial.println(str + ZERO.getMajorVersion() + "." + ZERO.getMinorVersion() + 
    ", HW Revision: " + ZERO.getHwRevision() + 
    ", SN: " + ZERO.getSerialNumber());
}

void loop()
{
    ZERO.startMeasure(FREQ);
    Serial.print(counter++);
    Serial.print(":\t");
    Serial.print("Frequency: 14 Mhz / ");
    Serial.print("SWR: ");
    Serial.print(ZERO.getSWR());
    Serial.print("\r\n");
    delay(5000);
}
